"""--------------家具类-----------"""

class Item:
    def __init__(self,name,area):
        """家具初始化方法

        Args:
            name (_type_): 家具名称
            area (_type_): 家具占地面积
        """
        self.name = name
        self.area = area
        
    def __str__(self):
        return "家具：{} 占地面积：{} ".format(self.name,self.area)
    
"""-------------房子类-----------"""
class house:
    
    def __init__(self,address,area):
        self.address = address  #地址
        self.area = area        #房子面积
        self.free_area = self.area #剩余面积
        self.items = []          #所有家具列表
        
    def __str__(self):
        return "地址：{} 占地面积：{} ".format(self.address,self.area)
    
    def add_item(self,item:Item):
        """添加家具到房子里
        剩余面积 >= 家具的面积时，允许添加
        param item:
             家具类Item的对象(实例)
        """
        if self.free_area >= item.area:
            self.items.append(item)
            self.free_area -= item.area
            print("添加成功：",item)
        else:
            print("面积不足，无法添加：",item)        
    
    
#创建对象
sofa = Item("沙发",5)
bed = Item("床",10)
desktop = Item("桌椅",30)
movie = Item("影院",130)
print(sofa)
print(bed)
print(desktop)
print(movie)

#对象
house = house("富春山居",150)

house.add_item(sofa)
house.add_item(bed)
house.add_item(desktop)
house.add_item(movie)

print(house)
print(house.items)